import {request} from "../../request/index.js"

Page({

  /**
   * 页面的初始数据
   */
  data: {
    array1: ['10kv','20kv','30kv'],
    value1: 0,
    disable: false,
    point_voltlevel:''
  },
  bindChange: function (e) {
    this.setData({
      value1: e.detail.value
    })
    this.setData({
      point_voltlevel: this.data.array1[e.detail.value]
    })
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    var that = this
    this.setData({
      point_voltlevel:this.data.array1[0]
    })   
  },
  
  formSubmit: function (e) {
    console.log(e)
    request({
      url: "/point/addPoint", 
      data: {
        pointCode:e.detail.value.pointCode,
        pointName:e.detail.value.pointName,
        pointLocation:e.detail.value.pointLocation,
        point_voltlevel: this.data.point_voltlevel,
        powerStation:e.detail.value.powerName
      }, 
      header: {
        'content-type': 'application/json' // 默认值
      }
    })
    .then(res => {
      if (res.statusCode == 200) {
        wx.showToast({
          title: '正在跳转',
          icon: 'success',
          duration: 2000
        })
        setTimeout(function () {
          wx.navigateTo({
            url: '../qrcode/qrcode?pointID='+res.data.pointID,
          })
        }, 2000)

        
      } else {
        wx.showToast({
          title: res.data.message,
          icon: 'none',
          duration: 2000
        })
      }
    })
  },

  codeInput: function(e) {
    if (!/^[A-Z][A-Z]([0-9]+)$/.test(e.detail.value)) { 
      wx.showToast({ title: '接地点编号输入有误，请重新输入', duration: 2000, icon:'none' }); 
    }
  }
})